package admin.dao;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import viewmodel.AdsEditStatus;

import model.Advertise;
import model.Connect;

public class AdsDAO {
	public static List<Advertise> getAllAds(){
		ArrayList<Advertise> listAds = new ArrayList<Advertise>();
		String sql = "SELECT * FROM eonl_advertise";
		try{
			Statement state = Connect.getConnection().createStatement();
			ResultSet result = state.executeQuery(sql);
			while(result.next()){
				Advertise ads = new Advertise(result.getInt("id"), result.getString("name"), result.getString("link"), result.getString("image"));
				listAds.add(ads);
			}
			result.close();
			state.close();
		}catch (Exception e) {
		}
		return listAds;
	}

	public static void updateAds(AdsEditStatus aes) {
		String sql = "UPDATE `eonl_advertise` SET name='"+aes.getAds().getName()+"',link='"+aes.getAds().getLink()+"',image='adversite/"+aes.getAds().getImage()+"' WHERE id="+aes.getAds().getId();
		try{
			Statement state = Connect.getConnection().createStatement();
			state.executeUpdate(sql);
			state.close();
		}catch (Exception e) {
		}
	}
}
